<!--
 * @Author: your name
 * @Date: 2020-12-21 14:19:49
 * @LastEditTime: 2020-12-21 14:49:05
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \basicjs\event\xhr\xhr.html
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./xhr.js"></script>
</head>
<body>
    <script>
        //发送GET请求
        // HD.get('xhr.php',{
        //     responseType:'text'
        // }).then((response) => {
        //     console.log(response);
        // });

        // HD.post('xhr.php',{name:'刘皓'},{
        //     responseType : 'json'
        // }).then((response) => {
        //     console.log(response)
        // });

        //GET
        //下面使用FETCH发送GET请求
        // fetch(`xhr.php`).then((response) => {
        //     return response.text(response);
        // }).then(data => {
        //     let p = document.createElement('p');
        //     p.innerHTML = data;
        //     document.body.appendChild(p);
        // })



        //POST
        //下面进行post进行请求操作
        
        //前台脚本
        fetch('xhr.php',{
            method:'POST',
            headers:{
                'Content-Type' : 'application/json;charset=utf-8',
            },
            body:JSON.stringify({name:'后盾人'}),
        })
        .then((response) => {
            return response.json();
        }).then((data) => {
            console.log(data);
        })
        ;
        



    </script>
</body>
</html>
